//包含所用头文件
#include "exti.h"
#include "led.h"
#include "key.h"
#include "delay.h"
#include "beep.h"
void EXTIX_Init(void)//外部中断初始化
{
 	EXTI_InitTypeDef EXTI_InitStructure;
  	NVIC_InitTypeDef NVIC_InitStructure;
    KEY_Init();//	①KEY_Init()按键端口初始化
  	RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);/*②开启IO口复用功能时钟使能*/	
  	GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource2); /*③设置IO口与中断线的映射关系：GPIOA.2（KEY2）--EXTI2*/
  	/*④初始化线上中断，设置触发条件等, 中断线2(EXTI2)以及中断初始化配置、下降沿触发*/
	EXTI_InitStructure.EXTI_Line=EXTI_Line2;//中断线2(EXTI2)，KEY2	
  	EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;	//中断
  	EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;//下降沿触发
  	EXTI_InitStructure.EXTI_LineCmd = ENABLE;//使能
  	EXTI_Init(&EXTI_InitStructure);	/*根据EXTI_InitStruct中指定的参数初始化外设EXTI寄存器*/ 
  	GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource3);/*设置IO口与中断线的映射关系：GPIOA.3（KEY3）--EXTI3*/
  	EXTI_InitStructure.EXTI_Line=EXTI_Line3;//中断线3(EXTI3)，KEY3
	EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;	
  	EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;//下降沿触发
  	EXTI_InitStructure.EXTI_LineCmd = ENABLE;//使能
  	EXTI_Init(&EXTI_InitStructure);/*根据EXTI_InitStruct中指定的参数初始化外设EXTI寄存器*/ 	  
  	GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource1);//设置IO口与中断线的映射关系：GPIOA.1（KEY1）--EXTI1
  	EXTI_InitStructure.EXTI_Line=EXTI_Line1;//中断线1(EXTI1)，KEY1
	EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;	
  	EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;//下降沿触发
  	EXTI_InitStructure.EXTI_LineCmd = ENABLE;//使能
  	EXTI_Init(&EXTI_InitStructure);	  
 	 GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource0); /*设置IO口与中断线的映射关系：GPIOA.0（KEY0）--EXTI0*/
  	EXTI_InitStructure.EXTI_Line=EXTI_Line0;//中断线0(EXTI0)，KEY0
	EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;	
  	EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;//下降沿触发
  	EXTI_InitStructure.EXTI_LineCmd = ENABLE;//使能
  	EXTI_Init(&EXTI_InitStructure);
     //⑤配置中断分组（NVIC），并使能中断
  	NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;/*使能按键KEY0所在的外部中断通道*/		
  	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x01;/*抢占优先级1*/
  	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00;	//响应优先级0
  	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//使能外部中断通道	
  	NVIC_Init(&NVIC_InitStructure); 
    NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQn;/*使能按键KEY1所在的外部中断通道*/			
  	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02;/*抢占优先级2*/
  	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01;//响应优先级1	
  	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;	//使能外部中断通道	
  	NVIC_Init(&NVIC_InitStructure);
  	NVIC_InitStructure.NVIC_IRQChannel = EXTI2_IRQn;/*使能按键KEY2所在的外部中断通道*/			
  	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02;/*抢占优先级2*/
  	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01;//响应优先级1	
  	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//使能外部中断通道	
  	NVIC_Init(&NVIC_InitStructure);  	  
	NVIC_InitStructure.NVIC_IRQChannel = EXTI3_IRQn;/*使能按键KEY3所在的外部中断通道*/		
  	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00;/*抢占优先级0*/
  	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00;	//响应优先级0
  	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;	/*使能外部中断通道*/		
  	NVIC_Init(&NVIC_InitStructure);  	
}
